﻿using Microsoft.AspNetCore.Mvc;

namespace Wosperry.QuartzJob.TestWebApi.Controllers
{
    [Route("api")]
    [ApiController]
    public class TestController : ControllerBase
    {
        private readonly IQuartzJobService _quartzJobService;

        public TestController(IQuartzJobService quartzJobService)
        {
            _quartzJobService = quartzJobService;
        }

        [HttpPut("test")]
        public async Task<string> TestAsync()
        {
            await _quartzJobService.StartAsync<MyJob>(options =>
            {
                options.TriggerName = "my_trigger"; // 触发器名，必须传，无默认值
                options.GroupName = "background_job"; // 分组名，默认"Default"
                options.JobName = "test_job"; // Job名字，必须传，如果同时运行多个任务，分组名+Job名不可重复
                options.Interval = (0,0,3); // 0时0分3秒，不给就10秒
                options.RepeatTimes = 4; // 重复次数，总次数=重复次数+1，不提供时一直循环不停止执行
            });

            return "开始了";
        }
    }
}
